<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Jekyll v4.0.1">
    <title>后台登录</title>

    <link rel="stylesheet" href="/static/bootstrap4/css/bootstrap.min.css">

    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            display: -ms-flexbox;
            display: flex;
            -ms-flex-align: center;
            align-items: center;
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #f5f5f5;
        }

        .form-signin {
            width: 100%;
            max-width: 330px;
            padding: 15px;
            margin: auto;
        }

        .form-signin .checkbox {
            font-weight: 400;
        }

        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }

        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }
    </style>
</head>
<body class="text-center">
<form class="form-signin" onsubmit="doLogin();return false;">
    <!--    <img class="mb-4" src="/docs/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">-->
    <h1 class="h3 mb-3 font-weight-normal">请登录</h1>
    <label for="username" class="sr-only">用户名</label>
    <input type="text" id="username" class="form-control" placeholder="用户名" required autofocus>
    <label for="password" class="sr-only">密码</label>
    <input type="password" id="password" class="form-control" placeholder="密码" required>
    <!--    <div class="checkbox mb-3">-->
    <!--        <label>-->
    <!--            <input type="checkbox" value="remember-me"> Remember me-->
    <!--        </label>-->
    <!--    </div>-->
    <button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
    <p class="mt-5 mb-3 text-muted">&copy; 2020</p>
</form>

<script src="/static/jquery-3.3.1.min.js"></script>
<script>
    function doLogin() {
        var username = $('#username').val();
        var password = $('#password').val();
        var data = {
            username: username,
            password: password
        };
        $.ajax({
            url: '/api/user/login',
            method: 'POST',
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(data),
            success: function (resp) {
                console.info(resp);
                if (resp.code === 200) {
                    window.location.href = '/studyroom/admin';
                } else {
                    alert(resp.message);
                }
            },
            error: function () {
            }
        });
    }
</script>
</body>
</html>
